package com.cnd.scm.orm.accessfilter;

/**
 * 模糊过滤条件构造器
 *
 * @author 李启联
 */
class AccessFilterLikeItem extends AccessFilterItem {
    protected boolean exactlyMatch;

    protected boolean isExactlyMatch() {
        return exactlyMatch;
    }

    /**
     * 模糊过滤条件构造器
     *
     * @param andCondition 使用 and 或者 or 条件拼接
     * @param filterKey    属性名称
     * @param filterValue  属性值
     * @param exactlyMatch (true 为全匹配  false 为模糊匹配)
     */
    AccessFilterLikeItem(boolean andCondition, String filterKey, Object filterValue, boolean exactlyMatch) {
        super(andCondition, filterKey, filterValue);
        this.exactlyMatch = exactlyMatch;
    }

    @Override
    public String toString() {
        if (exactlyMatch)
            return ((andCondition) ? " AND " : " OR ") + filterKey + " LIKE '" + filterValue + "'";
        else
            return ((andCondition) ? " AND " : " OR ") + filterKey + " LIKE '%" + filterValue + "%'";
    }
}